package com.yunhe.gateway;

import com.yunhe.gateway.util.SpringUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService;
import org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy;

@SpringBootApplication
@EnableEurekaClient
public class GatewayServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayServerApplication.class, args);
        //由于无法通过配置来修改gateway websocket传输内容的长度限制，所以直接修改webSocketService这个Bean的maxFramePayloadLength这个属性来增大长度限制
//        HandshakeWebSocketService webSocketService = SpringUtil.getBean("webSocketService");
//        if (webSocketService != null) {
//            ReactorNettyRequestUpgradeStrategy upgradeStrategy = (ReactorNettyRequestUpgradeStrategy) webSocketService.getUpgradeStrategy();
//            upgradeStrategy.setMaxFramePayloadLength(1024 * 1024 * 1024);
//        }
    }

//    /**
//     * 注入zuul过滤器
//     * 请求被路由之前
//     */
//    @Bean
//    public AuthenticationFilter preRequestFilter(){
//        return new AuthenticationFilter();
//    }
//
//    /**
//     * 注入zuul过滤器
//     * 请求被路由时
//     */
//    @Bean
//    public UrlRedirectFilter routeRequestFilter(){
//        return new UrlRedirectFilter();
//    }
//
//    /**
//     * Zuul使用正则表达式指定路由规则
//     * 您可以使用regexmapper提供serviceId和路由之间的约定。它使用名为组的正则表达式从serviceId中提取变量，并将其注入到路由模式中。
//     * @return
//     */
//    @Bean
//    public PatternServiceRouteMapper serviceRouteMapper() {
//        return new PatternServiceRouteMapper(
//                "(?<name>^.+)-(?<version>v.+$)",
//                "${version}/${name}");
//    }
}